var WxUtil = {
	init : function() {
		 
	},
	getOpenid : function(callfun) {
       // alert("11111");
	/*	if (!StringUtils.isWeixin()) {
			return;
		}*/
		var code = StringUtils.getUrlParam("code");
		var state = StringUtils.getUrlParam("state");
		if (StringUtils.isBlank(code) && !StringUtils.isBlank(state)) {
			return;
		}
		if (StringUtils.isBlank(StringUtils.GetLocalStorage("openid"))) {
			if (code != null) {
				    var sn =44;
					$.ajax({
						url : "/CdSystem2.0/core/api/weixinJSBridge/getWxUserInfo?code=" + code,
						dataType : "json",
						success : function(data) {
							if (data.result == 1) {
								StringUtils.SetLocalStorage("openid", data.message);
								if (typeof callfun === "function") {
									fun = callfun;
									fun();
								}
							} else {
								alert(data.message);
							}
						}
					});
			} else {
				var url = window.location.href;
				WxUtil.getWxUserCode(url);
			}
		}else{
			if (typeof callfun === "function") {
				fun = callfun;
				fun();
			}
		}
	},
	getWxUserCode : function(towordUrl) {
		/*if (!StringUtils.isWeixin()) {
			// 非微信，不获取
			return;
		}
*/
		var url = towordUrl;
		var redirect_uri = encodeURIComponent(url);
		var weixin_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc7d9603ff733d7e0";
		weixin_url += "&redirect_uri=";
		weixin_url += redirect_uri;
		weixin_url += "&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";
		window.location.href = weixin_url;
	}
}

